package logic

import (
	"context"
	"github.com/google/uuid"
	"week2_zg6/common/mysql"

	"week2_zg6/bookRpc/book"
	"week2_zg6/bookRpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderLogic {
	return &OrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderLogic) Order(in *book.OrderRequest) (*book.OrderResponse, error) {
	err := mysql.DB.Model(&mysql.Book{}).Create(&mysql.Orders{
		GoodsID:    int(in.GoodsID),
		OrderID:    uuid.New().String(),
		UserID:     int(in.UserID),
		Status:     0,
		TotalPrice: in.Price,
		Address:    in.Address,
	}).Error
	if err != nil {
		return nil, err
	}
	return &book.OrderResponse{}, nil
}
